/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hualu.zks.Dao;

import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class ConnDb {

    public static Connection conn = null;
    static String dburl = "";
    static String dbdriver = "";
    static String dbuser = "";
    static String dbpassword = "";

    public static Connection connDb() {

        Properties props = new Properties();
        //获取数据库配置文件信息
        try {
            FileInputStream in = null;
            in = new FileInputStream("jdbc.properties");
            props.load(in);
            
            dbdriver = props.getProperty("dbdriver_sqlite");
            dburl = props.getProperty("dburl_sqlite");

        } catch (IOException e) {
            System.err.println(e);
        }
//        if(conn!=null) {
//            return conn;
//        }
        //建立数据库连接
        try {
            System.out.println("dbdriver:" + dbdriver);
            System.out.println("dburl:" + dburl);
            Class.forName(dbdriver);
                conn = DriverManager.getConnection(dburl);
            if (!conn.isClosed()) {
                System.out.println("Succeeded connecting to the Database!");
            }
        } catch (ClassNotFoundException | SQLException e) {
        }
        if (null != conn) {
            return conn;
        } else {
            JOptionPane.showMessageDialog(null, "数据库连接失败！", "警告", JOptionPane.WARNING_MESSAGE);
            return null;
        }
    }
}
